import React,{useEffect,useState} from 'react'
const useInputValue = (initialValue,placeholder,type)=>{
    const [value,setValue] = useState(initialValue)
    const changeHandler = (e)=>{
        setValue(e.target.value)
    }
    const resetHandler = ()=>{
        setValue('')
    }
    return{
        value,
        placeholder,
        onChange:changeHandler,
        type,
        reset:resetHandler
    }
}
function Token({onSubmit}) {
    const [token,setToken] = useState('')
    const changeToken = (e)=>{
        setToken(e.target.value)
        sessionStorage.setItem('token',e.target.value)
    }
    const submitHandler = ()=>{
        onSubmit(text.value)
        reset()
    }
    const {reset,...text} = useInputValue("",'请输入用户名',"text")
    const password = useInputValue('','请输入密码',"password")
    return (
        <form onSubmit={submitHandler}>
            <input {...text}/>
            {/* <input {...password}/> */}
        </form>
    )
}

export default Token
